home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / linux / tools / gtar10.lha / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-10  |  16.8 KB  |  755 lines

  1. /* List a tar archive.
  2.    Copyright (C) 1988 Free Software Foundation
  3.  
  4. This file is part of GNU Tar.
  5.  
  6. GNU Tar is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Tar is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Tar; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /*
  21.  * List a tar archive.
  22.  *
  23.  * Also includes support routines for reading a tar archive.
  24.  *
  25.  * this version written 26 Aug 1985 by John Gilmore (ihnp4!hoptoad!gnu).
  26.  *
  27.  * @(#)list.c 1.31 11/5/87 - gnu
  28.  */
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #ifndef    MSDOS
  34. #include <sys/file.h>
  35. #endif    /* MSDOS */
  36.  
  37. #ifdef USG
  38. #include <sys/sysmacros.h>    /* major() and minor() defined here */
  39. #endif
  40.  
  41. char *ctime();                /* From libc.a */
  42.  
  43. #define    isodigit(c)    ( ((c) >= '0') && ((c) <= '7') )
  44.  
  45. #include "tar.h"
  46. #include "port.h"
  47.  
  48. extern FILE *msg_file;
  49.  
  50. long from_oct();            /* Decode octal number */
  51. void demode();                /* Print file mode */
  52.  
  53. union record *head;            /* Points to current archive header */
  54. struct stat hstat;            /* Stat struct corresponding */
  55. int head_standard;            /* Tape header is in ANSI format */
  56.  
  57. void print_header();
  58. void skip_file();
  59. void skip_extended_headers();
  60.  
  61. extern char *quote_copy_string();
  62.  
  63.  
  64. /*
  65.  * Main loop for reading an archive.
  66.  */
  67. void
  68. read_and(do_something)
  69.     void (*do_something)();
  70. {
  71.     int status = 3;            /* Initial status at start of archive */
  72.     int prev_status;
  73.     extern time_t new_time;
  74.     char save_linkflag;
  75.     
  76.     name_gather();            /* Gather all the names */
  77.     open_archive(1);        /* Open for reading */
  78.  
  79.     for(;;) {
  80.         prev_status = status;
  81.         status = read_header();
  82.         switch (status) {
  83.  
  84.         case 1:            /* Valid header */
  85.             /* We should decode next field (mode) first... */
  86.             /* Ensure incoming names are null terminated. */
  87.             head->header.name[NAMSIZ-1] = '\0';
  88.  
  89.             if (   !name_match(head->header.name)
  90.                  || (f_new_files && hstat.st_mtime<new_time)
  91.                  || (f_exclude && check_exclude(head->header.name))) {
  92.  
  93.                 int isextended = 0;
  94.  
  95.                 if(   head->header.linkflag==LF_VOLHDR
  96.                     || head->header.linkflag==LF_MULTIVOL
  97.                    || head->header.linkflag==LF_NAMES) {
  98.                     (*do_something)();
  99.                     continue;
  100.                 }
  101.                 /* Skip past it in the archive */
  102.                 if (head->header.isextended)
  103.                     isextended = 1;
  104.                 save_linkflag = head->header.linkflag;
  105.                 userec(head);
  106.                 if (isextended) {
  107. /*                    register union record *exhdr;
  108.  
  109.                     for (;;) {
  110.                         exhdr = findrec();
  111.                         if (!exhdr->ext_hdr.isextended) {
  112.                             userec(exhdr);
  113.                             break;
  114.                         }
  115.                     }
  116.                     userec(exhdr);*/
  117.                     skip_extended_headers();
  118.                 }
  119.                 /* Skip to the next header on the archive */
  120.                 if(save_linkflag != LF_DIR)
  121.                     skip_file((long)hstat.st_size);
  122.                 continue;
  123.  
  124.             }
  125.  
  126.             (*do_something)();
  127.             continue;
  128.  
  129.             /*
  130.              * If the previous header was good, tell them
  131.              * that we are skipping bad ones.
  132.              */
  133.         case 0:            /* Invalid header */
  134.             userec(head);
  135.             switch (prev_status) {
  136.             case 3:        /* Error on first record */
  137.                 msg("Hmm, this doesn't look like a tar archive.");
  138.                 /* FALL THRU */
  139.             case 2:        /* Error after record of zeroes */
  140.             case 1:        /* Error after header rec */
  141.                 msg("Skipping to next file header...");
  142.             case 0:        /* Error after error */
  143.                 break;
  144.             }
  145.             continue;
  146.  
  147.         case 2:            /* Record of zeroes */
  148.             userec(head);
  149.             status = prev_status;    /* If error after 0's */
  150.             if (f_ignorez)    
  151.                 continue;
  152.             /* FALL THRU */
  153.         case EOF:        /* End of archive */
  154.             break;
  155.         }
  156.         break;
  157.     };
  158.  
  159.     close_archive();
  160.     names_notfound();        /* Print names not found */
  161. }        
  162.  
  163.  
  164. /*
  165.  * Print a header record, based on tar options.
  166.  */
  167. void
  168. list_archive()
  169. {
  170.     extern char *save_name;
  171.     int    isextended = 0; /* Flag to remember if head is extended */
  172.     
  173.     /* Save the record */
  174.     saverec(&head);
  175.  
  176.     /* Print the header record */
  177.     if (f_verbose) {
  178.         if (f_verbose > 1)
  179.             decode_header(head, &hstat, &head_standard, 0);
  180.         print_header();
  181.     }
  182.  
  183.     if(f_gnudump && head->header.linkflag==LF_DUMPDIR) {
  184.         size_t    size, written, check;
  185.         char    *data;
  186.         extern int errno;
  187.         extern long save_totsize;
  188.         extern long save_sizeleft;
  189.  
  190.         userec(head);
  191.         if(f_multivol) {
  192.             save_name = head->header.name;
  193.             save_totsize=hstat.st_size;
  194.         }
  195.         for(size = hstat.st_size;size>0;size-=written) {
  196.             if(f_multivol)
  197.                 save_sizeleft=size;
  198.             data = findrec()->charptr;
  199.             if(data==NULL) {
  200.                 msg("EOF in archive file?");
  201.                 break;
  202.             }
  203.             written = endofrecs()->charptr - data;
  204.             if(written>size)
  205.                 written=size;
  206.             errno=0;
  207.             check=fwrite(data,sizeof(char), written, msg_file);
  208.             userec((union record *)(data+written - 1));
  209.             if(check!=written) {
  210.                 msg_perror("only wrote %ld of %ld bytes to file %s",check, written,head->header.name);
  211.                 skip_file((long)(size)-written);
  212.                 break;
  213.             }
  214.         }
  215.         if(f_multivol)
  216.             save_name = 0;
  217.         saverec((union record **) 0);    /* Unsave it */
  218.         fputc('\n',msg_file);
  219.         fflush(msg_file);
  220.         return;
  221.  
  222.     }
  223.     saverec((union record **) 0);    /* Unsave it */
  224.     /* Check to see if we have an extended header to skip over also */
  225.     if (head->header.isextended) 
  226.         isextended = 1;
  227.         
  228.     /* Skip past the header in the archive */
  229.     userec(head);
  230.  
  231.     /*
  232.       * If we needed to skip any extended headers, do so now, by
  233.       * reading extended headers and skipping past them in the 
  234.      * archive.
  235.      */
  236.     if (isextended) {
  237. /*        register union record *exhdr;
  238.  
  239.         for (;;) {
  240.             exhdr = findrec();
  241.  
  242.             if (!exhdr->ext_hdr.isextended) {
  243.                 userec(exhdr);
  244.                 break;
  245.             }
  246.             userec(exhdr);
  247.         }*/
  248.         skip_extended_headers();
  249.     }
  250.             
  251.     if(f_multivol)
  252.         save_name=head->header.name;
  253.     /* Skip to the next header on the archive */
  254.         
  255.     skip_file((long) hstat.st_size);
  256.         
  257.     if(f_multivol)
  258.         save_name = 0;
  259. }
  260.  
  261.  
  262. /*
  263.  * Read a record that's supposed to be a header record.
  264.  * Return its address in "head", and if it is good, the file's
  265.  * size in hstat.st_size.
  266.  *
  267.  * Return 1 for success, 0 if the checksum is bad, EOF on eof,
  268.  * 2 for a record full of zeros (EOF marker).
  269.  *
  270.  * You must always userec(head) to skip past the header which this
  271.  * routine reads.
  272.  */
  273. int
  274. read_header()
  275. {
  276.     register int    i;
  277.     register long    sum, recsum;
  278.     register char    *p;
  279.     register union record *header;
  280.     long    from_oct();
  281.  
  282.     header = findrec();
  283.     head = header;        /* This is our current header */
  284.     if (NULL == header)
  285.         return EOF;
  286.  
  287.     recsum = from_oct(8,  header->header.chksum);
  288.  
  289.     sum = 0;
  290.     p = header->charptr;
  291.     for (i = sizeof(*header); --i >= 0;) {
  292.         /*
  293.          * We can't use unsigned char here because of old compilers,
  294.          * e.g. V7.
  295.          */
  296.         sum += 0xFF & *p++;
  297.     }
  298.  
  299.     /* Adjust checksum to count the "chksum" field as blanks. */
  300.     for (i = sizeof(header->header.chksum); --i >= 0;)
  301.         sum -= 0xFF & header->header.chksum[i];
  302.     sum += ' '* sizeof header->header.chksum;    
  303.  
  304.     if (sum == recsum) {
  305.         /*
  306.          * Good record.  Decode file size and return.
  307.          */
  308.         if (header->header.linkflag == LF_LINK)
  309.             hstat.st_size = 0;    /* Links 0 size on tape */
  310.         else
  311.             hstat.st_size = from_oct(1+12, header->header.size);
  312.         return 1;
  313.     }
  314.  
  315.     if (sum == 8*' ') {
  316.         /*
  317.          * This is a zeroed record...whole record is 0's except
  318.          * for the 8 blanks we faked for the checksum field.
  319.          */
  320.         return 2;
  321.     }
  322.  
  323.     return 0;
  324. }
  325.  
  326.  
  327. /* 
  328.  * Decode things from a file header record into a "struct stat".
  329.  * Also set "*stdp" to !=0 or ==0 depending whether header record is "Unix
  330.  * Standard" tar format or regular old tar format.
  331.  *
  332.  * read_header() has already decoded the checksum and length, so we don't.
  333.  *
  334.  * If wantug != 0, we want the uid/group info decoded from Unix Standard
  335.  * tapes (for extraction).  If == 0, we are just printing anyway, so save time.
  336.  *
  337.  * decode_header should NOT be called twice for the same record, since the
  338.  * two calls might use different "wantug" values and thus might end up with
  339.  * different uid/gid for the two calls.  If anybody wants the uid/gid they
  340.  * should decode it first, and other callers should decode it without uid/gid
  341.  * before calling a routine, e.g. print_header, that assumes decoded data.
  342.  */
  343. decode_header(header, st, stdp, wantug)
  344.     register union record    *header;
  345.     register struct stat    *st;
  346.     int    *stdp;
  347.     int    wantug;
  348. {
  349.  
  350.     long from_oct();
  351.  
  352.     st->st_mode = from_oct(8,  header->header.mode);
  353. #ifdef amigados
  354.     if (amiga_perms)
  355.         st->st_amode = from_oct(1+12,  header->header.devmajor);
  356. #endif
  357.     st->st_mtime = from_oct(1+12, header->header.mtime);
  358.     if(f_gnudump) {
  359.         st->st_atime = from_oct(1+12, header->header.atime);
  360.         st->st_ctime = from_oct(1+12, header->header.ctime);
  361.     }
  362.     
  363.     if (0==strcmp(header->header.magic, TMAGIC)) {
  364.         /* Unix Standard tar archive */
  365.         *stdp = 1;
  366.         if (wantug) {
  367. #ifdef NONAMES
  368.             st->st_uid = from_oct(8,  header->header.uid);
  369.             st->st_gid = from_oct(8,  header->header.gid);
  370. #else
  371.             st->st_uid = finduid(header->header.uname);
  372.             st->st_gid = findgid(header->header.gname);
  373. #endif
  374.         }
  375.         switch (header->header.linkflag) {
  376.         case LF_BLK: case LF_CHR:
  377.             st->st_rdev = makedev(from_oct(8, header->header.devmajor),
  378.                        from_oct(8, header->header.devminor));
  379.         }
  380.     } else {
  381.         /* Old fashioned tar archive */
  382.         *stdp = 0;
  383.         st->st_uid = from_oct(8,  header->header.uid);
  384.         st->st_gid = from_oct(8,  header->header.gid);
  385.         st->st_rdev = 0;
  386.     }
  387. }
  388.  
  389.  
  390. /*
  391.  * Quick and dirty octal conversion.
  392.  *
  393.  * Result is -1 if the field is invalid (all blank, or nonoctal).
  394.  */
  395. long
  396. from_oct(digs, where)
  397.     register int    digs;
  398.     register char    *where;
  399. {
  400.     register long    value;
  401.  
  402.     while (isspace(*where)) {        /* Skip spaces */
  403.         where++;
  404.         if (--digs <= 0)
  405.             return -1;        /* All blank field */
  406.     }
  407.     value = 0;
  408.     while (digs > 0 && isodigit(*where)) {    /* Scan til nonoctal */
  409.         value = (value << 3) | (*where++ - '0');
  410.         --digs;
  411.     }
  412.  
  413.     if (digs > 0 && *where && !isspace(*where))
  414.         return -1;            /* Ended on non-space/nul */
  415.  
  416.     return value;
  417. }
  418.  
  419.  
  420. /*
  421.  * Actually print it.
  422.  *
  423.  * Plain and fancy file header block logging.
  424.  * Non-verbose just prints the name, e.g. for "tar t" or "tar x".
  425.  * This should just contain file names, so it can be fed back into tar
  426.  * with xargs or the "-T" option.  The verbose option can give a bunch
  427.  * of info, one line per file.  I doubt anybody tries to parse its
  428.  * format, or if they do, they shouldn't.  Unix tar is pretty random here
  429.  * anyway.
  430.  *
  431.  * Note that print_header uses the globals <head>, <hstat>, and
  432.  * <head_standard>, which must be set up in advance.  This is not very clean
  433.  * and should be cleaned up.  FIXME.
  434.  */
  435. #define    UGSWIDTH    11        /* min width of User, group, size */
  436. #define    DATEWIDTH    19        /* Last mod date */
  437. static int    ugswidth = UGSWIDTH;    /* Max width encountered so far */
  438.  
  439. void
  440. print_header()
  441. {
  442.     char modes[11];
  443.     char *timestamp;
  444.     char uform[11], gform[11];    /* These hold formatted ints */
  445.     char *user, *group;
  446.     char size[24];        /* Holds a formatted long or maj, min */
  447.     long longie;        /* To make ctime() call portable */
  448.     int    pad;
  449.     char *name;
  450.     extern long baserec;
  451.  
  452.     if(f_sayblock)
  453.         fprintf(msg_file,"rec %10d: ",baserec + (ar_record - ar_block));
  454.     /* annofile(msg_file, (char *)NULL); */
  455.  
  456.     if (f_verbose <= 1) {
  457.         /* Just the fax, mam. */
  458.         char *name;
  459.  
  460.         name=quote_copy_string(head->header.name);
  461.         if(name==0)
  462.             name=head->header.name;
  463.         fprintf(msg_file, "%s\n", name);
  464.         if(name!=head->header.name)
  465.             free(name);
  466.     } else {
  467.         /* File type and modes */
  468.         modes[0] = '?';
  469.         switch (head->header.linkflag) {
  470.         case LF_VOLHDR:
  471.             modes[0]='V';
  472.             break;
  473.  
  474.         case LF_MULTIVOL:
  475.             modes[0]='M';
  476.             break;
  477.  
  478.         case LF_NAMES:
  479.             modes[0]='N';
  480.             break;
  481.  
  482.         case LF_SPARSE:
  483.         case LF_NORMAL:
  484.         case LF_OLDNORMAL:
  485.         case LF_LINK:
  486.                 modes[0] = '-'; 
  487.                 if ('/' == head->header.name[strlen(head->header.name)-1])
  488.                     modes[0] = 'd';
  489.                 break;
  490.         case LF_DUMPDIR:modes[0] = 'd'; break;
  491.         case LF_DIR:    modes[0] = 'd'; break;
  492.         case LF_SYMLINK:modes[0] = 'l'; break;
  493.         case LF_BLK:    modes[0] = 'b'; break;
  494.         case LF_CHR:    modes[0] = 'c'; break;
  495.         case LF_FIFO:    modes[0] = 'p'; break;    
  496.         case LF_CONTIG:    modes[0] = 'C'; break;
  497.         }
  498.  
  499. #ifdef amigados
  500.         if (amiga_perms)
  501.             ademode ((unsigned)hstat.st_amode, modes+1);
  502.         else
  503. #endif
  504.         demode((unsigned)hstat.st_mode, modes+1);
  505.             
  506.  
  507.         /* Timestamp */
  508.         longie = hstat.st_mtime;
  509.         timestamp = ctime(&longie);
  510.         timestamp[16] = '\0';
  511.         timestamp[24] = '\0';
  512.  
  513.         /* User and group names */
  514.         if (*head->header.uname && head_standard) {
  515.             user  = head->header.uname;
  516.         } else {
  517.             user = uform;
  518.             (void)sprintf(uform, "%d", (int)hstat.st_uid);
  519.         }
  520.         if (*head->header.gname && head_standard) {
  521.             group = head->header.gname;
  522.         } else {
  523.             group = gform;
  524.             (void)sprintf(gform, "%d", (int)hstat.st_gid);
  525.         }
  526.  
  527.         /* Format the file size or major/minor device numbers */
  528.         switch (head->header.linkflag) {
  529.         case LF_CHR:
  530.         case LF_BLK:
  531.             (void)sprintf(size, "%d,%d",
  532.                     major(hstat.st_rdev),
  533.                     minor(hstat.st_rdev));
  534.             break;
  535.         case LF_SPARSE:
  536.             (void)sprintf(size, "%ld",
  537.                  from_oct(1+12, head->header.realsize));
  538.             break;
  539.         default:
  540.             (void)sprintf(size, "%ld", (long)hstat.st_size);
  541.         }
  542.  
  543.         /* Figure out padding and print the whole line. */
  544.         pad = strlen(user) + strlen(group) + strlen(size) + 1;
  545.         if (pad > ugswidth) ugswidth = pad;
  546.  
  547.         name = quote_copy_string(head->header.name);
  548.         if(!name)
  549.             name=head->header.name;
  550.         fprintf(msg_file, "%s %s/%s %*s%s %s %s %.*s",
  551.             modes,
  552.             user,
  553.             group,
  554.             ugswidth - pad,
  555.             "",
  556.             size,
  557.             timestamp+4, timestamp+20,
  558.             sizeof(head->header.name),
  559.             name);
  560.  
  561.         if(name!=head->header.name)
  562.             free(name);
  563.         switch (head->header.linkflag) {
  564.         case LF_SYMLINK:
  565.             name=quote_copy_string(head->header.linkname);
  566.             if(!name)
  567.                 name=head->header.linkname;
  568.             fprintf(msg_file, " -> %s\n", name);
  569.             if(name!=head->header.linkname)
  570.                 free(name);
  571.             break;
  572.  
  573.         case LF_LINK:
  574.             name=quote_copy_string(head->header.linkname);
  575.             if(!name)
  576.                 name=head->header.linkname;
  577.             fprintf(msg_file, " link to %s\n", head->header.linkname);
  578.             if(name!=head->header.linkname)
  579.                 free(name);
  580.             break;
  581.  
  582.         default:
  583.             fprintf(msg_file, " unknown file type '%c'\n",
  584.                 head->header.linkflag);
  585.             break;
  586.  
  587.         case LF_OLDNORMAL:
  588.         case LF_NORMAL:
  589.         case LF_SPARSE:
  590.         case LF_CHR:
  591.         case LF_BLK:
  592.         case LF_DIR:
  593.         case LF_FIFO:
  594.         case LF_CONTIG:
  595.         case LF_DUMPDIR:
  596.             putc('\n', msg_file);
  597.             break;
  598.  
  599.         case LF_VOLHDR:
  600.             fprintf(msg_file, "--Volume Header--\n");
  601.             break;
  602.             
  603.         case LF_MULTIVOL:
  604.             fprintf(msg_file, "--Continued at byte %ld--\n",from_oct(1+12,head->header.offset));
  605.             break;
  606.  
  607.         case LF_NAMES:
  608.             fprintf(msg_file,"--Mangled file names--\n");
  609.             break;
  610.         }
  611.     }
  612.     fflush(msg_file);
  613. }
  614.  
  615. /*
  616.  * Print a similar line when we make a directory automatically.
  617.  */
  618. void
  619. pr_mkdir(pathname, length, mode)
  620.     char *pathname;
  621.     int length;
  622.     int mode;
  623. {
  624.     char modes[11];
  625.     char *name;
  626.     extern long baserec;
  627.  
  628.     if (f_verbose > 1) {
  629.         /* File type and modes */
  630.         modes[0] = 'd';
  631.         demode((unsigned)mode, modes+1);
  632.  
  633.         if(f_sayblock)
  634.             fprintf(msg_file,"rec %10d: ",baserec + (ar_record - ar_block));
  635.         /* annofile(msg_file, (char *)NULL); */
  636.         name=quote_copy_string(pathname);
  637.         if(!name)
  638.             name=pathname;
  639.         fprintf(msg_file, "%s %*s %.*s\n",
  640.             modes,
  641.             ugswidth+DATEWIDTH,
  642.             "Creating directory:",
  643.             length,
  644.             pathname);
  645.         if(name!=pathname)
  646.             free(name);
  647.     }
  648. }
  649.  
  650.  
  651. /*
  652.  * Skip over <size> bytes of data in records in the archive.
  653.  */
  654. void
  655. skip_file(size)
  656.     register long size;
  657. {
  658.     union record *x;
  659.     extern long save_totsize;
  660.     extern long save_sizeleft;
  661.  
  662.     if(f_multivol) {
  663.         save_totsize=size;
  664.         save_sizeleft=size;
  665.     }
  666.  
  667.     while (size > 0) {
  668.         x = findrec();
  669.         if (x == NULL) {    /* Check it... */
  670.             msg("Unexpected EOF on archive file");
  671.             exit(EX_BADARCH);
  672.         }
  673.         userec(x);
  674.         size -= RECORDSIZE;
  675.         if(f_multivol)
  676.             save_sizeleft-=RECORDSIZE;
  677.     }
  678. }
  679.  
  680. void
  681. skip_extended_headers()
  682. {
  683.     register union record *exhdr;
  684.  
  685.     for (;;) {
  686.         exhdr = findrec();
  687.         if (!exhdr->ext_hdr.isextended) {
  688.             userec(exhdr);
  689.             break;
  690.         }
  691.         userec (exhdr);
  692.     }
  693. }
  694.  
  695. /*
  696.  * Decode the mode string from a stat entry into a 9-char string and a null.
  697.  */
  698. void
  699. demode(mode, string)
  700.     register unsigned mode;
  701.     register char *string;
  702. {
  703.     register unsigned mask;
  704.     register char *rwx = "rwxrwxrwx";
  705.  
  706.     for (mask = 0400; mask != 0; mask >>= 1) {
  707.         if (mode & mask)
  708.             *string++ = *rwx++;
  709.         else {
  710.             *string++ = '-';
  711.             rwx++;
  712.         }
  713.     }
  714.  
  715.     if (mode & S_ISUID)
  716.         if (string[-7] == 'x')
  717.             string[-7] = 's';
  718.         else
  719.             string[-7] = 'S';
  720.     if (mode & S_ISGID)
  721.         if (string[-4] == 'x')
  722.             string[-4] = 's';
  723.         else
  724.             string[-4] = 'S';
  725.     if (mode & S_ISVTX)
  726.         if (string[-1] == 'x')
  727.             string[-1] = 't';
  728.         else
  729.             string[-1] = 'T';
  730.     *string = '\0';
  731. }
  732.  
  733. #ifdef amigados
  734. void
  735. ademode (mode, string)
  736.     register unsigned mode;
  737.     register char *string;
  738. {
  739.     register unsigned mask;
  740.     register char *rwx = "?hsparwed";
  741.     register char *xor = "     xxxx";
  742.  
  743.     for (mask = 0400; mask != 0; mask >>= 1) {
  744.         if ((!!(mode & mask)) ^ (*xor++ == 'x'))
  745.             *string++ = *rwx++;
  746.         else {
  747.             *string++ = '-';
  748.             rwx++;
  749.         }
  750.     }
  751.  
  752.     *string = '\0';
  753. }
  754. #endif
  755.